﻿@model YouWei.Infrastructure.Entity.SmsCard
@{
    ViewBag.Title = "短信卡池";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        短信卡池管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li><a href="#" id="preBtn">短信卡池列表</a></li>
        <li class="active">短信卡池管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <form class="form-horizontal" id="form1">
                        <div class="box-body">
                            <input type="hidden" name="ID" value="@Model.CardID" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">卡所有人姓名</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtOwnerName" id="txtOwnerName" value="@Model.OwnerName" class="form-control" maxlength="255">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">卡所有人手机号</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtOwnerMobile" id="txtOwnerMobile" value="@Model.OwnerMobile" class="form-control" maxlength="11">
                                </div>
                            </div>
                            @if (Model.CardID > 0)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">端口号</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="txtPortNumber" id="txtPortNumber" value="@Model.PortNumber" class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">端口号</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="txtPortNumber" id="txtPortNumber" value="" class="form-control">
                                    </div>
                                </div>
                            }
                            <div class="form-group">
                                <label class="col-sm-2 control-label">通信制式类型</label>
                                <div class="col-sm-3">
                                    <select id="selType" name="selType" class="form-control">
                                        @foreach (int v in Enum.GetValues(typeof (YouWei.Infrastructure.Enums.SmsCardTelTypeEnum)))
                                        {
                                            if (v == Model.TelType)
                                            {
                                                <option selected value="@v">@YouWei.Utility.EnumHelper.GetEnumDesc(typeof (YouWei.Infrastructure.Enums.SmsCardTelTypeEnum), v)</option>
                                            }
                                            else
                                            {
                                                <option value="@v">@YouWei.Utility.EnumHelper.GetEnumDesc(typeof (YouWei.Infrastructure.Enums.SmsCardTelTypeEnum), v)</option>
                                            }
                                        }

                                    </select>

                                </div>
                            </div>

                            @if (Model.CardID > 0)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">每小时可发送短信数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="@Model.CountPerHour" name="txtCountPerHour" id="txtCountPerHour" class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">每小时可发送短信数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="" name="txtCountPerHour" id="txtCountPerHour" class="form-control">
                                    </div>
                                </div>
                            }


                            @if (Model.CardID > 0)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">每天可发送短信数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="@Model.CountPerDay" name="txtCountPerDay" id="txtCountPerDay" class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">每天可发送短信数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="" name="txtCountPerDay" id="txtCountPerDay" class="form-control">
                                    </div>
                                </div>
                            }

                           
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer text-center">
                            <button class="btn btn-info" type="button" id="btnSave">保存</button>
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
                <div class="box-footer clearfix ">
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        var userId = 0; //是否是添加页面，如果是编辑页则判断条件增加ID
        $(document).ready(function () {
            initFormValidate();
            binds();

        });

        //保存
        function save() {
            var bootstrapValidator = $("#form1").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                var url = '@Url.Action("SaveCard", "Sms")';
                var options = {
                    url: url,
                    type: "POST",
                    data: {
                        CardId: @Model.CardID,
                        txtPortNumber: $("#txtPortNumber").val(),
                        txtOwnerName: $("#txtOwnerName").val(),
                        txtOwnerMobile: $("#txtOwnerMobile").val(),
                        txtCountPerHour: $("#txtCountPerHour").val(),
                        txtCountPerDay: $("#txtCountPerDay").val(),
                        selTelType: $("#selType").val()
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("保存成功", function () {
                                location.href='@Url.Action("CarList", "Sms")';
                            });
                        } else {
                            BMCW.alert(o.message);
                        }
                    }
                };

                BMCW.ajax(options);
            }
        }
        function binds() {
            //保存
            $("#btnSave").click(function () {
                save();
            });
            $("#preBtn").click(function () {
                var url = '@Url.Action("CarList", "Sms")';
                location.href = url;
            })
        }


        //检查身份证是否存在
        function checkIdNumIsExist() {
            var url = "/User/IsExistIdNum";
            url += "?userId=" + userId + "&idnum=" + $("#txtIdNumber").val()
            var ajaxOption = {
                url: url,
                type: "GET",
                async: false,
                success: function (result) {
                    if (result.data == "1") {
                        $("#form1").data("bootstrapValidator").updateStatus("txtIdNumber", "INVALID", "exits");
                        BMCW.alert("身份证明号码已经存在");
                    } else {
                    }
                }
            };
            BMCW.ajax(ajaxOption);
        }

        function initFormValidate() {
            $("#form1").bootstrapValidator({
                submitHandler: function (valiadtor, loginForm, submitButton) {
                    valiadtor.defaultSubmit();
                },
                fields: {
                    txtOwnerName: {
                        validators: {
                            notEmpty: {
                                message: '请输入卡所有人姓名'
                            }
                        }
                    },
                    txtOwnerMobile: {
                        validators: {
                            notEmpty: {
                                message: '请输入卡所有人手机号'
                            }
                        }
                    },
                    txtPortNumber: {
                        validators: {
                            notEmpty: {
                                message: '请输入端口号'
                            }
                        }
                    },
                    txtCountPerHour: {
                        validators: {
                            notEmpty: {
                                message: '请输入每小时可发送短信数量'
                            },
                            regexp: {
                                regexp: /^[0-9]*$/,
                                message: '请输入数字'
                            },
                            callback: {
                                message: "请输入一个大于 0 的值",
                                callback: function (value, validator) {
                                    if (parseInt(value) > 0) {
                                        return true;
                                    }
                                    return false;
                                }
                            }
                        }
                    },

                    txtCountPerDay: {
                        validators: {
                            notEmpty: {
                                message: '请输入每天可发送短信数量'
                            },
                            regexp: {
                                regexp: /^[0-9]*$/,
                                message: '请输入数字'
                            },
                            callback: {
                                message: "请输入一个大于 0 的值",
                                callback: function (value, validator) {
                                    if (parseInt(value) > 0) {
                                        return true;
                                    }
                                    return false;
                                }
                            }
                        }
                    }
                }
            });
        }


    </script>
}




